package com.alibaba.csp.sentinel.demo.zuul.gateway.vo;

import lombok.Getter;
import lombok.Setter;

/**
 * @author xuzhao
 * Created by ace on 2017/8/23.
 */
public class BaseResultVo<T> {
    @Getter
    @Setter
    private int status = SUCCESS_CODE;

    @Getter
    @Setter
    private String message = SUCCESS_MSG;


    @Getter
    @Setter
    private String appTime;


    @Getter
    @Setter
    private T data;

    public static final Integer SUCCESS_CODE = 200;
    public static final Integer ERROR_CODE = 500;
    public static final Integer NOT_LOGIN = 300;
    public static final Integer PAYMENT_FAILURE = 301;

    public static final String SUCCESS_MSG = "操作成功";
    public static final String ERROR_MSG = "操作失败";
    public static final String NOT_LOGIN_MSG = "未登录";


    public BaseResultVo(T data, int status, String message) {
        this.status = status;
        this.message = message;
        this.data = data;
    }

    public BaseResultVo(T data) {
        this.data = data;
    }

    public BaseResultVo(int status, String message) {
        this.status = status;
        this.message = message;
    }

    public BaseResultVo() {
    }


    public static <T> BaseResultVo<T> success() {
        return new BaseResultVo<T>(SUCCESS_CODE, SUCCESS_MSG);
    }

    public static <T> BaseResultVo<T> success(T data) {
        return new BaseResultVo<T>(data, SUCCESS_CODE, SUCCESS_MSG);
    }

    public static <T> BaseResultVo<T> error(String message) {
        return new BaseResultVo<T>(ERROR_CODE, message);
    }

    public static <T> BaseResultVo<T> error() {
        BaseResultVo<T> baseResultVo = new BaseResultVo<T>();
        baseResultVo.setStatus(BaseResultVo.ERROR_CODE);
        baseResultVo.setMessage(BaseResultVo.ERROR_MSG);
        return baseResultVo;
    }

    public static <T> BaseResultVo<T> notLogin() {
        return new BaseResultVo<T>(NOT_LOGIN, NOT_LOGIN_MSG);
    }

    public static <T> BaseResultVo<T> error(Integer code, String message) {
        return new BaseResultVo<T>(code, message);
    }

    @Override
    public String toString() {
        return "BaseResultVo{" +
                "status=" + status +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }
}
